package com.trkj.controller;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojos.CcGenre;
import com.trkj.pojos.CcPatient;
import com.trkj.pojos.CcWard;
import com.trkj.service.CcBerthService;
import com.trkj.service.CcPatientService;
import com.trkj.service.CcStoreyService;
import com.trkj.service.CcTrimService;
import com.trkj.service.CcWardService;
import com.trkj.vo.CcBerthVo;
import com.trkj.vo.CcPatientVo;
import com.trkj.vo.CcWardVo;
import com.trkj.vo.Result;

@Controller
public class CcWardController {

	@Autowired
	private CcWardService ccward;
	@Autowired
	private CcBerthService ccBerthService;
	@Autowired
	private CcPatientService cpService;
	@Autowired
	private CcTrimService ctService;
	@Autowired
	private CcStoreyService cstService;
	
	@RequestMapping("/cc_ward")
	public String tohost(){
		return "cc_ward";
	}
	@RequestMapping("/cc_hosp_electronic")
	public String tocc_hosp_electronic(){
		return "cc_hosp_electronic";
	}
	@RequestMapping("/tocc_queryWardHremarks")
	public @ResponseBody Map<String, Object> toqueryWard(int page,int rows){
		return ccward.queryWardHremarks(page,rows);
	}
	@RequestMapping("/tocc_queryAllWard")
	public @ResponseBody Map<String, Object> toqueryAllWard(int page,int rows){
		return ccward.queryAllWard(page,rows);
	}
	@RequestMapping("/tocc_queryByWname")
	public @ResponseBody List<CcBerthVo> toqueryWname(String wname){
		return ccBerthService.queryByWname(wname);
	}
	@RequestMapping("/tocc_findBywname")
	public @ResponseBody List<CcWardVo> tofidbywname(String wname){
		return ccward.queryBywardwname(wname);
	}
	@RequestMapping("/tocc_findBydepartmentName")
	public @ResponseBody List<CcWardVo> tofidbydepartmentName(String departmentName){
		return ccward.queryBywarddepartmentName(departmentName);
	}
	@RequestMapping("/tocc_findBywardGename")
	public @ResponseBody List<CcWardVo> tofindBygename(String gename){
		return ccward.queryBywardGename(gename);
	}
	@RequestMapping("/tocc_queryBydepartmentName")
	public @ResponseBody List<CcBerthVo> toquerydepartmentName(String departmentName){
		return ccBerthService.queryBydepartmentName(departmentName);
	}
	@RequestMapping("/tocc_findByAllCcGenre")
	public @ResponseBody List<CcGenre> tofindByAllCcGenre(){
		return ccward.queryAllCcGenre();
	}
	@RequestMapping("/tocc_findByGename")
	public @ResponseBody List<CcBerthVo> tofindByGename(String gename){
		return ccBerthService.queryByGename(gename);
	}
	@RequestMapping("/tocc_findByberthstate")
	public @ResponseBody Map<String, Object> tofindByberthstate(String state,int page,int rows){
		
		Map<String, Object> map=ccBerthService.findByberthstate(state,page,rows);
		return  map;
	}
	@RequestMapping("/tocc_findByStorey")
	public @ResponseBody Map<String, Object> tofindByStorey(){
		
		return  cstService.queryAllStorey();
	}
	@RequestMapping("/tocc_queryALLberth")
	public @ResponseBody Map<String, Object> toqueryALLBerth(int page,int rows){
		
		Map<String, Object> map=ccBerthService.queryALLberth(page,rows);
		return  map;
	}
	@RequestMapping("/tocc_queryAllberth")
	public @ResponseBody Map<String, Object> toqueryAllBerth(String bwardno){
		
		Map<String, Object> map=ccBerthService.querywberth(bwardno);
		return  map;
	}
	@RequestMapping("/tocc_querynullpaberthid")
	public @ResponseBody Map<String, Object> toquerynullpaberthid(int page,int rows){
		
		return  cpService.querynullpaberthid(page,rows);
	}
	@RequestMapping("/tocc_querynotnullpaberthid")
	public @ResponseBody Map<String, Object> toquerynotnullpaberthid(int page,int rows){
		
		return  cpService.querynotnullpaberthid(page,rows);
	}
	@RequestMapping("/addberthp")
	public @ResponseBody Result addberthp(String bertnid,String patientid){
		long bid=Long.parseLong(bertnid);
		long pid=Long.parseLong(patientid);
		ccBerthService.updateBerth(bid, new BigDecimal(patientid));
		cpService.upCcPatient(pid, new BigDecimal(bertnid));
		return new Result(true, "办理成功！");		
	}
	@RequestMapping("/cc_addWard")
	public @ResponseBody Result addWard(String wname,String wberth,String wmoney, String wofficesId,
			String wgenreid,String wstoId){
		if(wberth==null){
			wberth=0+"";
		}
		ccward.addWard(wname, wberth, wmoney, wofficesId, wgenreid, wstoId);
		return new Result(true, "添加成功！");		
	}
	@RequestMapping("/cc_updateWard")
	public @ResponseBody Result updateWard(String wid,CcWard cw){
		cw.setWardid(Long.parseLong(wid));
		ccward.updateccward(cw);
		return new Result(true, "修改成功！");		
	}
	@RequestMapping("/findByccwardId")
	public @ResponseBody CcWard findByccwardId(long wid){
		return ccward.findByccwardId(wid);
	}
	@RequestMapping("/addWardBerth")
	public @ResponseBody Result addWardBerth(String wid){
		ccward.addWardBerth(wid);
		return new Result(true, "添加成功！");		
	}
	@RequestMapping("/delWardBerth")
	public @ResponseBody Result delWardBerth(Long[] bid){
		ccward.delWardBerth(bid);
		return new Result(true, "床位撤除成功！");		
	}
	@RequestMapping("/cc_addtrim")
	public @ResponseBody Result addtrim(String thandleid,String thisbid,String ttremarks,String trimbid,String trimpbid){
		
		boolean jg=ctService.addCcTrim(thandleid, thisbid, ttremarks, trimbid, trimpbid);
		if(jg){
			return new Result(true,"调整成功!");	
		}else{
			return new Result(false,"调整失败!");	
		}
			
	}
}
